/**
 * 包含多个基于 state 的 getter 计算属性的对象
 */

export default {
  // 基于 state.cartFoods 的计算属性
  totalCount(state) {
    return state.cartFoods.reduce((preTotal, food) => preTotal + food.count, 0)
  },
  totalPrice(state) {
    return state.cartFoods.reduce((preTotal, food) => preTotal + food.count * food.price, 0)
  },

  // 基于 state.ratings 的计算属性
  positiveSize(state) {
    return state.ratings.reduce((preTotal, rating) => preTotal + (rating.rateType===0 ? 1 : 0), 0)
  },
}
